package com.fuyun.web.controller.plan;

import com.fuyun.common.annotation.Log;
import com.fuyun.common.core.controller.BaseController;
import com.fuyun.common.core.domain.AjaxResult;
import com.fuyun.common.core.page.tableDataInfo;
import com.fuyun.common.enums.BusinessType;
import com.fuyun.common.utils.poi.ExcelUtil;
import com.fuyun.plan.bo.TPlanProcessingAddBo;
import com.fuyun.plan.bo.TPlanProcessingEditBo;
import com.fuyun.plan.bo.TPlanProcessingQueryBo;
import com.fuyun.plan.service.ITPlanProcessingService;
import com.fuyun.plan.vo.TPlanProcessingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 染色计划Controller
 *
 * @author Amy
 * @date 2021-05-18
 */
@Api(value = "染色计划控制器" , tags = {"染色计划管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/plan/dye")
public class TPlanProcessingController extends BaseController {

    private final ITPlanProcessingService iTPlanProcessingService;

    /**
     * 查询染色计划列表
     */
    @ApiOperation("查询染色计划列表")
    @PreAuthorize("@ss.hasPermi('plan:dye:list')")
    @GetMapping("/list")
    public tableDataInfo<TPlanProcessingVo> list(TPlanProcessingQueryBo bo) {
        startPage();
        List<TPlanProcessingVo> list = iTPlanProcessingService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出染色计划列表
     */
    @ApiOperation("导出染色计划列表")
    @PreAuthorize("@ss.hasPermi('plan:dye:export')")
    @Log(title = "染色计划" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TPlanProcessingVo> export(TPlanProcessingQueryBo bo) {
        List<TPlanProcessingVo> list = iTPlanProcessingService.queryList(bo);
        ExcelUtil<TPlanProcessingVo> util = new ExcelUtil<TPlanProcessingVo>(TPlanProcessingVo.class);
        return util.exportExcel(list, "染色计划");
    }

    /**
     * 获取染色计划详细信息
     */
    @ApiOperation("获取染色计划详细信息")
    @PreAuthorize("@ss.hasPermi('plan:dye:query')")
    @GetMapping("/{id}")
    public AjaxResult<TPlanProcessingVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iTPlanProcessingService.queryById(id));
    }

    /**
     * 新增染色计划
     */
    @ApiOperation("新增染色计划")
    @PreAuthorize("@ss.hasPermi('plan:dye:add')")
    @Log(title = "染色计划" , businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TPlanProcessingAddBo bo) {
        return toAjax(iTPlanProcessingService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改染色计划
     */
    @ApiOperation("修改染色计划")
    @PreAuthorize("@ss.hasPermi('plan:dye:edit')")
    @Log(title = "染色计划" , businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TPlanProcessingEditBo bo) {
        return toAjax(iTPlanProcessingService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除染色计划
     */
    @ApiOperation("删除染色计划")
    @PreAuthorize("@ss.hasPermi('plan:dye:remove')")
    @Log(title = "染色计划" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTPlanProcessingService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
